<template>
<div class="photoslist-container">
    <div id="slider" class="mui-slider">
        <!-- 图片分类 -->
        <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
            <div class="mui-scroll">
                <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" href="#" data-wid="tab-top-subpage-1.html" 
                    v-for="item in category" :key="item.id" @click="getPhotoList(item.id)">{{ item.title }}</a>
            </div>
        </div>
        <!-- 图片列表 -->
        <div class="photolist">
            <router-link class="photo-item" v-for="item in photoslist" :key="item.id"
                 :to="'/home/photosdetail/' + item.id" tag="div">
                <img v-lazy="item.img_url" alt="">
                <div class="photo-content">
                    <div class="photo-title">{{ item.title }}</div>
                    <div class="content">{{ item.content }}</div>
                </div>
            </router-link>
        </div>
  </div>
</div>
  
</template>

<script>
// 导入导航栏滑动js
import mui from '../../lib/mui/js/mui.min.js'
export default {
    data(){
        return {
            category: [],
            photoslist: []
        }
    },
    created(){
        this.getCategory()
        this.getPhotoList(0)
    },
    methods: {
        getCategory(){  // 获取图片分类
            this.$http.get('api/getimgcategory').then(result => {
                if(result.body.status === 0){
                    this.category = result.body.message
                    this.category.unshift({"title": "全部", "id": 0})
                }else{

                }
            })
        },
        getPhotoList(cateId){   // 获取图片列表
            this.$http.get('api/getimages/' + cateId).then(result => {
                console.log(result)
                if(result.body.status === 0){
                    this.photoslist = result.body.message
                }else{

                }
            })
        }
    },
    mounted(){
        mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		});
    }
};
</script>

<style lang="scss" scoped>
* {
  touch-action: pan-y;
}

.mui-scroll{
    border-radius: 9px;
    color: rgb(65, 105, 225);
    margin-top: 1px;
    box-shadow: inset 0 5px 5px #bbc;
    .mui-control-item{
        background-image: linear-gradient(to top, #dedede, #c8c8c8, #dedede);
        border-radius: 12px 12px 0 0;
        border: 1px solid #e1e1e0;
    }
    .mui-active{
        color: white !important;
        background-color: rgba(65, 105, 225, 0.9) !important;
    }
}

.photolist{
    padding: 10px;
    .photo-item{
        position: relative;
        box-shadow: 0 0 9px #999;
        margin-bottom: 10px;
        color: #fff;
        img{
            width: 100%;
            vertical-align: middle;
        }
        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        }
        .photo-content{
            position: absolute;
            width: 100%;
            margin: 2px;
            background-color: rgba(0, 0, 0, 0.4);
            bottom: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            max-height: 84px;
            .photo-title{
                font-size: 14px;
                font-weight: bold;
                
            }
            .content{
                font-size: 13px;
            }
        }
    }
}
</style>